﻿<UserControl x:Class="RentAWorker.RIA.Page"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
    xmlns:ctl="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" 
	xmlns:ria="clr-namespace:RentAWorker.RIA"
    MinWidth="500" MinHeight="300"
    Loaded="UserControl_Loaded">

	<UserControl.Resources>
		<ImageBrush x:Key="BackgroundImageBrush" ImageSource="Images/Background.png" Stretch="UniformToFill" />
		
		<ria:HourGridHelper x:Key="HourGridHelperObject" />
	</UserControl.Resources>

	<Grid x:Name="LayoutRoot" Background="{StaticResource BackgroundImageBrush}">
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto" />
			<!-- Row for header image -->
			<RowDefinition Height="*" />
			<!-- Content row -->
		</Grid.RowDefinitions>

		<!-- Header image (animated; fades in after loaded event) -->
		<Image Grid.Row="0" Source="Images/Header.png" Margin="10" x:Name="HeaderImage" Opacity="0">
			<Image.Triggers>
				<EventTrigger RoutedEvent="Image.Loaded">
					<EventTrigger.Actions>
						<BeginStoryboard>
							<BeginStoryboard.Storyboard>
								<Storyboard Storyboard.TargetName="HeaderImage"
											Storyboard.TargetProperty="Opacity">
									<DoubleAnimation From="0" To="1" Duration="0:0:3" BeginTime="0:0:3" />
								</Storyboard>
							</BeginStoryboard.Storyboard>
						</BeginStoryboard>
					</EventTrigger.Actions>
				</EventTrigger>
			</Image.Triggers>
		</Image>

		<!-- Content area -->
		<ctl:TabControl Margin="10" Grid.Row="1">
			<ctl:TabItem Header="Tools">
				<Grid>
					<Grid.RowDefinitions>
						<RowDefinition Height="Auto" />
						<RowDefinition Height="*" />
					</Grid.RowDefinitions>

					<!-- Filter area -->
					<StackPanel Grid.Column="0" Grid.Row="0" Orientation="Horizontal">
						<ComboBox Margin="5" 
								  ItemsSource="{Binding MachineTypeList}" 
								  SelectedItem="{Binding SelectedMachineType, Mode=TwoWay}" 
								  DisplayMemberPath="MachineTypeName" 
								  Width="150" />
						<ctl:DatePicker Margin="5" SelectedDate="{Binding SelectedDate,Mode=TwoWay}" />
					</StackPanel>

					<!-- DataGrid with content -->
					<data:DataGrid Grid.Column="0" Grid.Row="1" 
								   AutoGenerateColumns="False" 
								   ItemsSource="{Binding GroupedRentalServiceList}" 
								   IsReadOnly="True"
								   Background="{StaticResource BackgroundImageBrush}">
						<data:DataGrid.Columns>
							<data:DataGridTextColumn Binding="{Binding Key.ResourceID}" Header="Resource ID" />
							<data:DataGridTextColumn Binding="{Binding Key.RessourceName}" Header="Name" />
							<data:DataGridTemplateColumn MinWidth="550">
								<data:DataGridTemplateColumn.CellTemplate>
									<DataTemplate>
										<Grid>
											<ItemsControl ItemsSource="{Binding Source={StaticResource HourGridHelperObject}, Path=HourGrid}" 
												          HorizontalContentAlignment="Stretch"
														  Background="White">
												<ItemsControl.ItemTemplate>
													<DataTemplate>
														<Border HorizontalAlignment="Stretch" 
																BorderBrush="Blue" 
																BorderThickness="1,0,0,0" />
													</DataTemplate>
												</ItemsControl.ItemTemplate>
												<ItemsControl.ItemsPanel>
													<ItemsPanelTemplate>
														<ria:TimeLine />
													</ItemsPanelTemplate>
												</ItemsControl.ItemsPanel>
											</ItemsControl>
											<ItemsControl ItemsSource="{Binding Value}" 
														  HorizontalContentAlignment="Stretch"
														  Background="Transparent">
												<ItemsControl.ItemTemplate>
													<DataTemplate>
														<Border Background="DarkGray" 
																Opacity="0.75"
																HorizontalAlignment="Stretch" 
																Margin="3"
																ToolTipService.ToolTip="{Binding Path=StartDate}"
																CornerRadius="3" />
													</DataTemplate>
												</ItemsControl.ItemTemplate>
												<ItemsControl.ItemsPanel>
													<ItemsPanelTemplate>
														<ria:TimeLine />
													</ItemsPanelTemplate>
												</ItemsControl.ItemsPanel>
											</ItemsControl>
										</Grid>

									</DataTemplate>
								</data:DataGridTemplateColumn.CellTemplate>
							</data:DataGridTemplateColumn>
						</data:DataGrid.Columns>
					</data:DataGrid>
				</Grid>
			</ctl:TabItem>
			<ctl:TabItem Header="Worker">
				<data:DataGrid AutoGenerateColumns="False" ItemsSource="{Binding WorkerList}"
                               IsReadOnly="True">
					<data:DataGrid.Columns>
						<data:DataGridTextColumn Binding="{Binding ResourceID}" Header="Resource ID"/>
						<data:DataGridTextColumn Binding="{Binding RessourceName}" Header="Name"/>
						<data:DataGridTextColumn Binding="{Binding SSNo}" Header="SV Nr"/>
						<data:DataGridTextColumn Binding="{Binding Location.LocationName}" Header="Location"/>
					</data:DataGrid.Columns>
				</data:DataGrid>
			</ctl:TabItem>
		</ctl:TabControl>
	</Grid>
</UserControl>
